package com.xebest.web.controller.finance;

import com.xebest.api.fin.dto.ManagerFinRefundDetailPageDTO;
import com.xebest.api.fin.dto.ManagerFinRefundPageDto;
import com.xebest.api.fin.dto.XeSysFinRefundDetailRequestDTO;
import com.xebest.api.fin.dto.XeSysFinRefundRequestDTO;
import com.xebest.api.fin.service.XeSysFinRefundRestApiService;
import com.xebest.common.base.controller.BaseController;
import com.xebest.common.base.controller.BaseResponse;
import com.xebest.util.SysSetBeanUtils;
import com.xebest.web.view.ErpUserInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 财务冲销单
 *
 * @author wangyp
 */
@RestController
@RequestMapping("finRefund")
public class XeSysFinRefundController extends BaseController {
    private final Logger log = LoggerFactory.getLogger(XeSysFinRefundController.class);
    //账单退款单业务类
    @Autowired
    private XeSysFinRefundRestApiService xeSysFinRefundRestApiServicevice;

    /**
     * 财务冲销单列表
     *
     * @author wangyp
     */
    @RequestMapping("/listSysFinRefund")
    public BaseResponse listSysFinRefund(@RequestBody XeSysFinRefundRequestDTO dto) {
        log.info("财务冲销单查询--start：");
        try {
            ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
            dto.setUserCode(userInfo.getUserCode());
            setType(dto);
            ManagerFinRefundPageDto billDto = xeSysFinRefundRestApiServicevice.listSysFinRefund(dto);
            Map<String, Object> resMap = new HashMap<>();
            resMap.put("billDto", billDto.getList());
            resMap.put("page", billDto.getXePageInfoDto());
            return sendAjaxOK(resMap);
        } catch (Exception e) {
            log.info("财务冲账单信息查询接口,异常:", e);
            return sendAjaxError();
        }
    }

    /**
     * 设置查询类型
     */
    private void setType(XeSysFinRefundRequestDTO dto) {
        if (null != dto.getSearchType()) {
            switch (dto.getSearchType()) {
                case 1:
                    break;
                case 2:
                    dto.setPbCode(dto.getRbCode());
                    dto.setRbCode(null);
                    break;
                default:
                    break;
            }
        }
    }

    /**
     * 财务冲销单明细列表
     *
     * @author wangyp
     */
    @RequestMapping("/listFinRefundDetail")
    public BaseResponse listFinRefundDetail(@RequestBody XeSysFinRefundDetailRequestDTO dto) {
        log.info("财务冲销单明细查询--start：");
        try {
            ManagerFinRefundDetailPageDTO refundDetailDto = xeSysFinRefundRestApiServicevice.listFinRefundDetail(dto);
            Map<String, Object> resMap = new HashMap<>();
            resMap.put("refundDetailDto", refundDetailDto.getList());
            resMap.put("page", refundDetailDto.getXePageInfoDto());
            return sendAjaxOK(resMap);
        } catch (Exception e) {
            log.info("财务冲账单信息查询接口,异常:", e);
            return sendAjaxError();
        }
    }

}
